// pages/my/my.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        userInfo:{},
        openid:''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onShow: function (options) {
        console.log("dffff")
        const openid = wx.getStorageSync('openid')
        const userInfo = wx.getStorageSync('userInfo')
        this.setData({
            openid,
            userInfo
        })
       
    },
    login(e){
       
        wx.getUserProfile({
            desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
            success: (res) => {
                console.log(res.userInfo)
              this.setData({
                userInfo: res.userInfo,
                hasUserInfo: true
              })
              wx.login({
                //获取code
               
                success:  (res)=> {
                  var code = res.code; //返回code
                  const userInfo = this.data.userInfo
                  wx.setStorageSync("userInfo",userInfo);
                  wx.request({
                      url: 'http://127.0.0.1:6060/api/addUserInfo',
                      data: {
                          code,
                          userInfo
                        
                      },
                      header: {'content-type':'application/json'},
                      method: 'post',
                     
                      success: (result) => {
                          console.log(result.data.message)
                          this.setData({
                              openid:result.data.message
                          })
                          wx.setStorageSync("openid",result.data.message);
                      },
                     
                  });
                    
                }
            })
              wx.showToast({
                  title: '登录成功',
                  icon: 'success',
                 
                  duration: 1500,
                  mask: false,
                  success: (result) => {
                      
                  },
                  fail: () => {},
                  complete: () => {}
              });
                
           
            }
          })
        }
        
})